﻿@{
    ViewBag.Title = "Index";
    Layout = "~/Views/Shared/_ManufactureList.cshtml";
}
<script>
    $(function () {
        $('#layout').layout();
        treeView();
        gridList();
    });
    function treeView() {
        $("#itemTree").treeview({
            url: "/MainData/ItemsType/GetTreeJson",
            onnodeclick: function (item) {
                $("#txt_keyword").val('');
                $('#btn_search').trigger("click");
                if ($("#itemTree").getCurrentNode().parentnodes != '0') {
                    if ($('#btn_add').hasClass("disabled")) {
                        $('#btn_add').removeClass("disabled")
                    }
                } else {
                    if (!$('#btn_add').hasClass("disabled")) {
                        $('#btn_add').addClass("disabled")
                    }
                }
            }
        });
    }
    function gridList() {
        var $gridList = $("#gridList");
        $gridList.dataGrid({
            height: $(window).height() - 106,
            colModel: [
                { label: "主键", name: "FTypeID", hidden: true, key: true },
                { label: '编号', name: 'FTypeNO', width: 150, align: 'left' },
                { label: '名称', name: 'FTypeName', width: 150, align: 'left' },
                { label: '排序', name: 'SortCode', width: 80, align: 'center' },
                {
                    label: "有效", name: "FEnabled", width: 60, align: "center", formatter: function (cellvalue) {
                        return cellvalue == '1' ? "是" : "否";
                    }
                },
                { label: '创建人员', name: 'FCreateBy', width: 80, align: 'left', sortable: false },
                { label: '创建日期', name: 'FCreateDate', width: 80, align: 'center', sortable: false },
                { label: '创建时间', name: 'FCreateTime', width: 80, align: 'center', sortable: false },
                { label: '更改人员', name: 'FUpdateBy', width: 80, align: 'left', sortable: false },
                { label: '更改日期', name: 'FUpdateDate', width: 80, align: 'center', sortable: false },
                { label: '更改时间', name: 'FUpdateTime', width: 80, align: 'center', sortable: false },
                { label: "备注", name: "", index: "", width: 170, align: "left", sortable: false }
            ],
            rownumWidth: 40,
            loadComplete: function () {
                if (!$('#btn_remove').hasClass("disabled")) {
                    $('#btn_remove').addClass("disabled");
                }
                if (!$('#btn_edit').hasClass("disabled")) {
                    $('#btn_edit').addClass("disabled");
                }
            },
            onSelectRow: function (rowid) {
                if ($('#btn_remove').hasClass("disabled")) {
                    $('#btn_remove').removeClass("disabled");
                }
                if ($('#btn_edit').hasClass("disabled")) {
                    $('#btn_edit').removeClass("disabled");
                }
            }
        });
        $gridList.jqGrid('setLabel', 0, '序号', 'rowNumberHeaderStyle');
        $("#btn_search").click(function () {
            $gridList.jqGrid('setGridParam', {
                url: "/MainData/ItemsData/GetGridJson",
                postData: { itemId: $("#itemTree").getCurrentNode().id, keyword: $("#txt_keyword").val() },
            }).trigger('reloadGrid');
        });
    }
    function btn_add() {
        var itemId = $("#itemTree").getCurrentNode().id;
        var itemName = $("#itemTree").getCurrentNode().text;
        if (!itemId) {
            return false;
        }
        $.modalOpen({
            id: "Form",
            title: itemName + " 》新增字典",
            url: "/MainData/ItemsData/Form?itemId=" + itemId,
            width: "450px",
            height: "350px",
            callBack: function (iframeId) {
                top.frames[iframeId].submitForm();
            }
        });
    }
    function btn_edit() {
        var itemName = $("#itemTree").getCurrentNode().text;
        var keyValue = $("#gridList").jqGridRowValue().FTypeID;
        $.modalOpen({
            id: "Form",
            title: itemName + " 》修改字典",
            url: "/MainData/ItemsData/Form?keyValue=" + keyValue,
            width: "450px",
            height: "350px",
            callBack: function (iframeId) {
                top.frames[iframeId].submitForm();
            }
        });
    }
    function btn_remove() {
        $.deleteForm({
            url: "/MainData/ItemsData/DeleteForm",
            param: { keyValue: $("#gridList").jqGridRowValue().FTypeID },
            success: function () {
                $("#gridList").resetSelection();
                $("#gridList").trigger("reloadGrid");
            }
        })
    }
    function btn_itemstype() {
        $.modalOpen({
            id: "ItemsType",
            title: "字典分类",
            url: "/MainData/ItemsType/Index",
            width: "800px",
            height: "550px",
            btn: null,
        });
    }
</script>
<div class="ui-layout" id="layout" style="height: 100%; width: 100%;">
    <div class="ui-layout-west">
        <div id="itemTree"></div>
    </div>
    <div class="ui-layout-center">
        <div style="padding: 12px 10px 5px 0; padding-left: 15px; border-bottom: 1px solid #ccc; " class="line-table input-width-140">
            <div class="btn-group" style="margin-top:-9px;">
                编号/名称<br /><input id="txt_keyword" name="txt_keyword" type="text" class="form-control " /> &nbsp;
            </div>
            <div class="btn-group" style="">
                <a id="btn_search" class="btn btn-primary center-block" onclick=""><span class="glyphicon glyphicon-search"></span> 检索</a>
            </div>
            <div class="btn-group" style="float:right;">
                <a id="" class="btn btn-primary center-block" onclick="$.reload()"><span class="glyphicon glyphicon-refresh"></span> 刷新</a>
                <a id="btn_itemstype" class="btn btn-primary center-block" onclick="btn_itemstype()"><span class="glyphicon glyphicon-th-list"></span> 分类管理</a>
                <a id="btn_add" class="btn btn-primary center-block disabled" onclick="btn_add()"><span class="glyphicon glyphicon-plus"></span> 新增</a>
                <a id="btn_remove" class="btn btn-primary center-block disabled" onclick="btn_remove()"><span class="glyphicon glyphicon-trash"></span> 删除</a>
                <a id="btn_edit" class="btn btn-primary center-block disabled" onclick="btn_edit()"><span class="glyphicon glyphicon-edit"></span> 修改</a>
                <a id="" class="btn btn-primary center-block disabled" onclick=""><span class="glyphicon glyphicon-download"></span> 导出</a>
            </div>
        </div>
        <div style="margin-left:5px">
            <table id="gridList"></table>
        </div>
    </div>
</div>
